<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>工作组管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@include file="/WEB-INF/ibnms/common/ztree.jsp" %>
</head>

<body>
<div class="form-wrapper">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">工作组管理</span>
             </h3>
        </div>
        <s:if test='%{theForm.WORKGROUP_ID!=null && !theForm.WORKGROUP_ID.equals("0")}'>
	        <div class="box-in" style="display:none">
	            <table border="0" cellspacing="0" cellpadding="0" class="table-03">
		            <tr>
			         	<td class="monitor_bg1" height="13"  width="150px" nowrap>
			         		工作组名称：
				         </td>
				         <td class="monitor_bg1">
				         	${theForm.WORKGROUP_NAME}
				         </td>
				   </tr>
				   <tr>
				         <td class="monitor_bg1" height="13"  nowrap>
				         	是否有效：
				         </td>
				         <td class="monitor_bg1">
				     		<s:if test='%{theForm.LOCKSTATE==null||!theForm.LOCKSTATE.equals("1")}'>
									有效
							</s:if>
							<s:if test='%{theForm.LOCKSTATE.equals("1")}'>
									无效
							</s:if>
				         </td>
			   		</tr>
			   		<tr>
			   			<td class="monitor_bg1" height="13"  nowrap>
				     		工作组说明：
				         </td>
				         <td class="monitor_bg1">
				         	${theForm.WORKGROUP_DESC}
				         </td>
			   		</tr>
	            </table>
	        </div>
        	<div class="title-style"><a class="fold-tip unfold-tip"></a></div>
        </s:if>
        <div id="role-form" class="block02">
        	<input type="hidden" name="theForm.SUPER_WG" value="${theForm.SUPER_WG}"></input>
			<input type="hidden" name="theForm.WORKGROUP_ID" value="${theForm.WORKGROUP_ID}"></input>
        	<div class="title-style02">
	        	<input class="btn-style02" type="button" id="btn-addWorkGroup" value="新建组">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-editWorkGroup" value="修改组">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-delWorkGroup" value="删除组">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-addUser" value="添加人员">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-removeUser" value="移除人员">&nbsp;&nbsp;
			</div>
			<table id="gridTable" width="80%">
			</table>
			<div id="gridPager">
			</div>
			<form id="workGroupForm" name="workGroupForm" method="post">
			</form>
		</div>
</div>

</body>
		<script type="text/javascript">
			$(function(){
				$(".title-style a.fold-tip").toggle(toggletip,toggletip);
				function toggletip() {
					if ($(this).attr("class").split("unfold-tip").length > 1) {
						$(this).removeClass("unfold-tip");
						$(this).parents().prev(".box-in").show("fast");
					} else {
						$(this).addClass("unfold-tip");
						$(this).parents().prev(".box-in").hide("fast");
					}
				}
			});
			
			$(function(){
				$("#gridTable").jqGrid({
					url: "loadWorkGroupUserListQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "auto",
					autowidth: true,
					colNames:['LOGIN_ID', '姓名', '电话'],
					colModel:[
						{name:'LOGIN_ID',index:'LOGIN_ID',hidden:true},
						{name:'NAME',index:'NAME'},
						{name:'LOGIN_PHONE',index:'LOGIN_PHONE'}
					],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }      
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true,
					beforeRequest:function(){
						var postData = {};
						$(":input[name^='theForm.']").each(function(){
							postData[$(this).attr("name")] = $(this).val();
						});
						$.extend($("#gridTable").getGridParam("postData"), postData);
					}
				});
				
			}); 
			
			
			$("#btn-addWorkGroup").click(function(){
				var parentId = $("input[name='theForm.WORKGROUP_ID']").val();
				$("form[name='workGroupForm']").attr("action","<s:url action='editWorkGroup' namespace='/'/>?theForm.SUPER_WG="+parentId).submit();
			});
			$("#btn-delWorkGroup").click(function(){
				if(confirm("确定解散该工作组?")){
					var id = $("input[name='theForm.WORKGROUP_ID']").val();
					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action='deleteWorkGroup' namespace='/'/>?theForm.WORKGROUP_ID="+id,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       		parent.refreshNode();
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			});
			$("#btn-editWorkGroup").click(function() {
				var id = $("input[name='theForm.WORKGROUP_ID']").val();
				$("form[name='workGroupForm']").attr("action","<s:url action='editWorkGroup' namespace='/'/>?theForm.WORKGROUP_ID="+id);
				$("form[name='workGroupForm']").submit();
			}); 
			
			$("#btn-addUser").click(function() {
				var selectUser = window.showModalDialog('<%=application.getContextPath()%>/loadUserManage.do?type=select','选择用户','help:no;scroll:no;status:no;dialogHeight:600px;dialogWidth:900px');
		   		if(selectUser!=undefined){
		   			var WORKGROUP_ID = $("input[name='theForm.WORKGROUP_ID']").val();
		   			var id = "";
		   			for (var one in selectUser){
                    	id = id + selectUser[one].LOGIN_ID + ",";
                    }
                    if(id.length>0){
                    	id = id.substring(0,id.length-1);
                    }
					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action='addWorkGroupUser' namespace='/'/>?theForm.WORKGROUP_ID="+WORKGROUP_ID+"&id="+id,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
				}
			}); 
			$("#btn-removeUser").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要移除的人员!");
                    return;
                }
                
				if(confirm("是否移除所选的人员?")){
					var WORKGROUP_ID = $("input[name='theForm.WORKGROUP_ID']").val();
					var loginId = "";
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	loginId += data.LOGIN_ID + ",";
                    }
                    if(loginId.length>0){
                    	loginId = loginId.substring(0,loginId.length-1);
                    }
					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="removeWorkGroupUser" namespace='/'/>?theForm.WORKGROUP_ID="+WORKGROUP_ID+"&id="+loginId,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       		parent.refreshNode();
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			}); 
			
		</script>
</html>
